package com.itboye.mengwu.app.adapter;

import java.util.ArrayList;

import com.itboye.mengwu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ItemAdapter extends BaseAdapter {
	 ArrayList<String> strs1 = new ArrayList<String>();
	  ArrayList<String> strs2 = new ArrayList<String>();
	  ArrayList<String> strs3 = new ArrayList<String>();
	  ArrayList<String> strs4 = new ArrayList<String>();
	  
	  ListView little;
	
	
	ArrayList<String> strs = new ArrayList<String>();
	Context context;
	int position;

	public ItemAdapter(Context context, ArrayList<String> strs,ListView little) {
		super();
		this.strs = strs;
		this.context = context;
		this.little =little;
		strs1.add("a1");
		strs1.add("a2");
		strs1.add("a3");
		strs1.add("a4");
		strs1.add("a5");
		strs1.add("a6");
		
		strs2.add("b1");
		strs2.add("b2");
		strs2.add("b3");
		strs2.add("b4");
		strs2.add("b5");
		strs2.add("b6");
		
		strs3.add("c1");
		strs3.add("c2");
		strs3.add("c3");
		strs3.add("c4");
		strs3.add("c5");
		strs3.add("c6");
		
		strs4.add("d1");
		strs4.add("d2");
		strs4.add("d3");
		strs4.add("d4");
		strs4.add("d5");
		strs4.add("d6");

	}

	@Override
	public int getCount() {

		return (strs != null & strs.size() > 0 ? strs.size() : 0);
	}

	@Override
	public Object getItem(int position) {

		return (strs != null & strs.size() > 0 ? strs.get(position) : null);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		this.position= position;
		ViewHolder holder;
		LayoutInflater layoutInflater = LayoutInflater.from(context);
		if (convertView == null) {
			holder = new ViewHolder();

			convertView = layoutInflater.inflate(R.layout.item_fenlei_textview, null);
			holder.title = (TextView) convertView.findViewById(R.id.text);
			holder.lineLayout = (RelativeLayout) convertView.findViewById(R.id.lineLayout);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.title.setText(strs.get(position));
		holder.lineLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
			
				
				if(position== 0){
					Item2Adapter adapte2 = new Item2Adapter(context, strs1);
					little.setAdapter(adapte2);
				}
				if(position== 1){
					Item2Adapter adapte2 = new Item2Adapter(context, strs2);
					little.setAdapter(adapte2);
				}
				if(position== 2){
					Item2Adapter adapte2 = new Item2Adapter(context, strs3);
					little.setAdapter(adapte2);
				}
				if(position== 3){
					Item2Adapter adapte2 = new Item2Adapter(context, strs4);
					little.setAdapter(adapte2);
				}
				
			}
		});

		return convertView;

	}
	class ViewHolder {
		public TextView title;
		public RelativeLayout lineLayout;

	}


}